package com.fanpan26.source.concurrent;

import java.util.Arrays;
import java.util.ListIterator;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author fanpan26
 */
public class CopyOnWriteArrayListSourceCode {

    public static void main(String[] args) {
        CopyOnWriteArrayList<String> array = new CopyOnWriteArrayList<>();

        array.add("a");
        array.add("b");
        array.add("c");
        array.add("d");
        array.add("d");

        array.set(3,"t");
        //c
        System.out.println("array.get(2)=" + array.get(2));

        //e
        array.add(5, "e");
        System.out.println("array.get(5)=" + array.get(5));

        //false
        System.out.println("array.addIfAbsent(\"d\")=" + array.addIfAbsent("d"));

        //true
        System.out.println(" array.contains(\"a\")=" + array.contains("a"));

        //5
        System.out.println(" array.size()=" + array.size());
        //false
        System.out.println(" array.isEmpty()=" + array.isEmpty());
        ListIterator<String> iterator = array.listIterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        array.clear();


        String[] array1 = new String[]{"1","2","3","4"};

        String[] newArray1=new String[5];
        System.arraycopy(array1,0,newArray1,0,array1.length);

    }

}
